class Common {
  String _sdCardDir;

  String get sdCardDir => this._sdCardDir;

  set sdCardDir(String dir) => this._sdCardDir = dir;

  // 工厂方法
  factory Common() => _getInstance();

  static Common _instance; // 静态实例

  // 单例模式
  static Common _getInstance() {
    if (_instance == null) {
      _instance = Common._internal();
    }
    return _instance;
  }

  static Common get instance => _getInstance();

  Common._internal();

//=========================
  String sDCardDir;
  static const _1B = 1024; // 1b
  static const _1KB = 1024 * 1024; // 1kb
  static const _1MB = 1024 * 1024 * 1024; // 1MB
  static const _1GB = 1024 * 1024 * 1024 * 1024; // 1MB

// 获取文件大小
  String getFileSize(int fileSize) {
    String size = '';
    if (fileSize < _1B) {
      size = '${fileSize.toStringAsFixed(2)}B';
    } else if (1024 <= fileSize && fileSize < _1KB) {
      size = '${fileSize.toStringAsFixed(2)}KB';
    } else if (_1KB <= fileSize && fileSize < _1MB) {
      size = '${fileSize.toStringAsFixed(2)}MB';
    } else if (_1MB <= fileSize && fileSize < _1GB) {
      size = '${fileSize.toStringAsFixed(2)}GB';
    }
    return size;
  }

//=========================
// 根据文件拓展设置图标
  String selectIcon(String ext) {
    String iconImg = 'assset/images/unknown.png';
    switch (ext) {
      case '.ppt':
        iconImg = 'assset/images/ppt.png';
        break;
      case '.doc':
      case '.docx':
        iconImg = 'assset/images/word.png';
        break;
      case '.ppt':
        iconImg = 'assset/images/ppt.png';
        break;
      case '.xls':
      case '.xlsx':
        iconImg = 'assset/images/excel.png';
        break;
      case '.jpg':
      case '.jpeg':
      case '.png':
        iconImg = 'assset/images/image.png';
        break;
      case '.txt':
        iconImg = 'assset/images/txt.png';
        break;
      case '.mp3':
        iconImg = 'assset/images/mp3.png';
        break;
      case '.mp4':
        iconImg = 'assset/images/mp4.png';
        break;
      case '.rar':
        iconImg = 'assset/images/rar.png';
        break;
      case '.zip':
        iconImg = 'assset/images/zip.png';
        break;
      case '.psd':
        iconImg = 'assset/images/psd.png';
        break;
      default:
        iconImg = 'assset/images/file.png';
        break;
    }
    return iconImg;
  }
}
